home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Advanced F202025292001.psc / Form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-05-28  |  5.7 KB  |  185 lines

  1. VERSION 5.00
  2. Begin VB.Form frmParent 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2535
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2535
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CheckBox Check1 
  13.       Caption         =   "Show Options (Page 2)"
  14.       Height          =   255
  15.       Left            =   120
  16.       TabIndex        =   4
  17.       Top             =   2040
  18.       Width           =   3015
  19.    End
  20.    Begin VB.TextBox Text1 
  21.       Height          =   285
  22.       Left            =   1440
  23.       TabIndex        =   1
  24.       Text            =   "Text1"
  25.       Top             =   120
  26.       Width           =   3135
  27.    End
  28.    Begin VB.PictureBox Picture2 
  29.       BorderStyle     =   0  'None
  30.       Height          =   1215
  31.       Left            =   2400
  32.       ScaleHeight     =   1215
  33.       ScaleWidth      =   2055
  34.       TabIndex        =   3
  35.       Top             =   600
  36.       Width           =   2055
  37.    End
  38.    Begin VB.PictureBox Picture1 
  39.       BorderStyle     =   0  'None
  40.       Height          =   1215
  41.       Left            =   120
  42.       ScaleHeight     =   1215
  43.       ScaleWidth      =   2055
  44.       TabIndex        =   2
  45.       Top             =   600
  46.       Width           =   2055
  47.    End
  48.    Begin VB.CommandButton Command1 
  49.       Caption         =   "Command1"
  50.       Height          =   375
  51.       Left            =   3360
  52.       TabIndex        =   5
  53.       Top             =   2040
  54.       Width           =   1215
  55.    End
  56.    Begin VB.Label Label1 
  57.       Caption         =   "Main Host Form"
  58.       Height          =   255
  59.       Left            =   120
  60.       TabIndex        =   0
  61.       Top             =   120
  62.       Width           =   1215
  63.    End
  64. Attribute VB_Name = "frmParent"
  65. Attribute VB_GlobalNameSpace = False
  66. Attribute VB_Creatable = False
  67. Attribute VB_PredeclaredId = True
  68. Attribute VB_Exposed = False
  69. Option Explicit
  70. #Const Demo1 = 0        '## Set to 1 to view 'in-App-Form' Demo
  71.                         '   or '0' for 'in-process-DLL' Demo
  72. '## Child form hWnd
  73. Private mlF2Ptr As Long
  74. Private mlF3Ptr As Long
  75. Private mlF4Ptr As Long
  76. '## Child's parent hWnd
  77. Private mlP2Ptr As Long
  78. Private mlP3Ptr As Long
  79. Private mlP4Ptr As Long
  80. '## Picture Container Next item hWnd in tab order
  81. Private mlFocus1Ptr As Long
  82. Private mlFocus2Ptr As Long
  83. '## Child form declarations
  84. Private WithEvents oF2 As Form2
  85. Attribute oF2.VB_VarHelpID = -1
  86. Private WithEvents oF3 As Form3
  87. Attribute oF3.VB_VarHelpID = -1
  88. #If Demo1 Then
  89.     Private WithEvents oF4 As Form4
  90. Attribute oF4.VB_VarHelpID = -1
  91. #Else
  92.     '## a class is used as an passthrough process as
  93.     '   forms are not exposed from DLLs
  94.     Private WithEvents oF4 As pDllForm.cForm1
  95. Attribute oF4.VB_VarHelpID = -1
  96. #End If
  97. Private Sub Check1_Click()
  98.     '## Switching disblayed forms
  99.     Select Case Check1.Value
  100.         Case 0
  101.             '## Release current child form and hide
  102.             pReleaseContainer mlF4Ptr, mlP4Ptr
  103.             oF4.Visible = False
  104.             '## Assign new child form and show
  105.             mlP3Ptr = pAssignContainer(mlF3Ptr, Picture2.hWnd)
  106.             oF3.Visible = True
  107.         Case 1
  108.             pReleaseContainer mlF3Ptr, mlP3Ptr
  109.             oF3.Visible = False
  110.             mlP4Ptr = pAssignContainer(mlF4Ptr, Picture2.hWnd)
  111.             oF4.Visible = True
  112.     End Select
  113. End Sub
  114. Private Sub Form_Load()
  115.     Set oF2 = New Form2
  116.     Set oF3 = New Form3
  117. #If Demo1 Then
  118.     Set oF4 = New Form4
  119. #Else
  120.     Set oF4 = New pDllForm.cForm1
  121. #End If
  122.     mlF2Ptr = oF2.hWnd
  123.     mlF3Ptr = oF3.hWnd
  124.     mlF4Ptr = oF4.hWnd
  125.     pSetWinStyle mlF2Ptr
  126.     pSetWinStyle mlF3Ptr
  127.     pSetWinStyle mlF4Ptr
  128.     mlP2Ptr = pAssignContainer(mlF2Ptr, Picture1.hWnd)
  129.     mlP3Ptr = pAssignContainer(mlF3Ptr, Picture2.hWnd)
  130.     oF2.Visible = True
  131.     oF3.Visible = True
  132.     mlFocus1Ptr = Picture2.hWnd
  133.     mlFocus2Ptr = Check1.hWnd
  134. End Sub
  135. Private Sub Form_Unload(Cancel As Integer)
  136.     pReleaseContainer mlF2Ptr, mlP2Ptr
  137.     Select Case Check1.Value
  138.         Case 0: pReleaseContainer mlF3Ptr, mlP3Ptr
  139.         Case 1: pReleaseContainer mlF4Ptr, mlP4Ptr
  140.     End Select
  141.     Unload oF2
  142.     Unload oF3
  143.     Set oF2 = Nothing
  144.     Set oF3 = Nothing
  145. #If Demo1 Then
  146.     Unload oF4
  147. #End If
  148.     Set oF4 = Nothing
  149. End Sub
  150. Private Sub pSetWinStyle(hWnd As Long)
  151.     Dim dwStyle As Long
  152.     '## set the form's window style
  153.     dwStyle = GetWindowLong(hWnd, GWL_STYLE)
  154.     dwStyle = dwStyle Or WS_CHILD
  155.     SetWindowLong hWnd, GWL_STYLE, dwStyle
  156. End Sub
  157. '## Assign a child form to the parent container
  158. Private Function pAssignContainer(lFrmPtr As Long, lPicPtr As Long) As Long
  159.     pAssignContainer = SetParent(lFrmPtr, lPicPtr)
  160.     '## move the form flush inside the picturebox frame
  161.     Call SetWindowPos(lFrmPtr, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE)
  162. End Function
  163. '## Must be called to release the child form from the parent container
  164. Private Sub pReleaseContainer(lFrmPtr As Long, lParentPtr As Long)
  165.     SetParent lFrmPtr, lParentPtr
  166. End Sub
  167. Private Sub oF2_MoveFocus()
  168.     '## Do not use .SetFocus method as we are shifting focus between
  169.     '   two forms
  170.     Call winSetFocus(mlFocus1Ptr) '## Manually select next object in tab
  171.                                   '   order on parent form
  172. End Sub
  173. Private Sub oF3_MoveFocus()
  174.     Call winSetFocus(mlFocus2Ptr)
  175. End Sub
  176. Private Sub oF4_MoveFocus()
  177.     Call winSetFocus(mlFocus2Ptr)
  178. End Sub
  179. Private Sub Picture1_GotFocus()
  180.     Call winSetFocus(mlF2Ptr)   '## Shift focus to child form
  181. End Sub
  182. Private Sub Picture2_GotFocus()
  183.     Call winSetFocus(IIf(Check1.Value = 0, mlF3Ptr, mlF4Ptr))
  184. End Sub
  185.